<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">

	$(function(){
		
		 test(31,true,0.5,0.5,0.8,3);
	
	})
	
	/**
	* 用户报价行为 用map集合 包裹，包括 公司或者组织名 + 报价具体数额，
	但是这里为了方便排序 选择以 报价数额为key 公司或者组织名为value
	如  var obj = {'100':'你好啊1','300':'你好啊3','200':'你好啊2'}; 
	*
	*
	*/
	function test(mark,isPL,F1,F2,F3,bidNum) {
		//报价
		var map={'100.9':'公司1','300':'公司2','200':'公司3'};
		var a = [];  
	    $.each(map, function(key, val) { a[a.length] = key;  });  
		a.sort(sortNumber);
		//var list = bidPrice.split(",",bidNum);
		var markList = {} ;
		//list.sort(sortNumber);
		/*$.each(a,function(index,value){
			alert(value);
		})*/
		var start = 0, end = a.length -1;
		//是否需要计算偏离
		if(isPL){ 
			if(a[0] > a[1] * (1 +  F1) && a[end]  < a[ end -1 ] * F2){
				start = 1;
				end = end -1;
			}
			else if(a[0] <= a[1] * (1 +  F1) && a[end]  < a[ end -1 ] * F2){ 
				end = end -1;
			}
			else if(a[0] > a[1] * (1 +  F1) && a[end]  >= a[ end -1 ] * F2){
				start = 1;
			}
		}
		console.log(start,end);
		 
		var Aavg = 0,sum = 0;
		for(var i = start;i <= end;i++){
			sum += parseFloat(a[i]);
			console.log(sum);
		}
		Aavg = sum / (end - start + 1);
		console.log('sum :' + sum );
		console.log('Aavg :' + Aavg );
		console.log('F3 ' + F3);
		$.each(a,function(index,value){
			console.log(index + ",  " + value + ",  "  +  Math.abs(value - Aavg) * 100 * F3 / Aavg);
			
			var values = mark - Math.abs(value - Aavg) * 100 * F3 / Aavg;
		 
			console.log(values);
			if(values < 0) values = 0;
			else
				values = values.toFixed(2);
			markList[map[value]] = values;
				
		})
		
		console.log(markList);
	} 
	
	function test1(){
		var map = {};
		map['500'] = 'key1';
		map['100'] = 'key2';
		map['3060.9'] = 'key3';
		var a = [];  
	    $.each(map, function(key, val) { a[a.length] = key;  });  
		a.sort(sortNumber);
		$.each(a,function(index,value){
			alert(map[value]);
		})
	}
	function sortMap(a,b){
		return 1
	}
	
	function sortNumber(a,b){
		  return b - a;
		}
</script>
</head>
<body>
</body>
</html>